package com.rjjs.Xiaozhi.tools;


import com.rjjs.Xiaozhi.entity.Appointment;
import com.rjjs.Xiaozhi.service.AppointmentService;
import dev.langchain4j.agent.tool.Tool;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class AppointmentTools {

    @Autowired
    private AppointmentService appointmentService;

    @Tool(name="预约观园",value = "根据参数，并直接给用户回答是否可以预约，并让用户确定是否预约信息，用户确定后再进行预约")
    public String addAppointment(Appointment appointment){
        Appointment appointmentDb = appointmentService.getOne(appointment);
       appointment.setId(null);
       if(appointmentDb==null){
           if (appointmentService.save(appointment)){
               return "预约成功，并返回预约详情";
           }else {
               return "预约失败";
           }
       }
        return "您在相同的科室和时间已有预约";
    }
    @Tool(name = "取消预约",value = "根据参数，查询预约是否存在，如果存在则删除预约记录并返回取\n" +
            "消预约成功，否则返回取消预约失败")
    public String cancelAppointment(Appointment appointment){
        Appointment appointmentDb = appointmentService.getOne(appointment);
        if(appointmentDb!=null){
            //删除预约记录
            if(appointmentService.removeById(appointmentDb.getId())){
                return "取消预约成功";
            }else{
                return "取消预约失败";
            }
        }
        //取消失败
        return "您没有预约记录，请核对预约信息和时间";
    }


}
